package com.dc.trans.steps.bwzh;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2009</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;



public class DMHelper {
    private List listBusiService = null;

    private static DMHelper instance=null;
    public static DMHelper getInstance()
    {
        if(instance == null)
            instance = new DMHelper();
        return instance;
    }

    public DMHelper() {
    }

    public static String sepChar = ";";
    public static String sepParaChar = ",";
    public static String equalChar = "=";
    public  Map splitSingleService(String strSource)
    {
        HashMap retMap = new HashMap();
        if (strSource == null || "".equals(strSource))
            return retMap;

        String paras = "";
        String wfparas = "";
        String[] arrParas = null;
        String[] arrWfparas = null;
        String[] s = strSource.split(sepChar);
        int length = s.length;
        for (int i = 0; i < length; i++) {
            if (s[i].startsWith("appname=")) {
                retMap.put("appname",
                           s[i].substring("appname=".length(), s[i].length()));
            }
//            else
//            if (s[i].startsWith("classname=")) {
//                retMap.put("classname",
//                           s[i].substring("classname=".length(), s[i].length()));
//            }
//            else
//            if (s[i].startsWith("methodname=")) {
//                retMap.put("methodname",
//                           s[i].substring("methodname=".length(), s[i].length()));
//            }
//            else
//            if (s[i].startsWith("returntype=")) {
//                retMap.put("returntype",
//                           s[i].substring("returntype=".length(), s[i].length()));
//            }
//            else
//            if (s[i].startsWith("returnvalue=")) {
//                retMap.put("returnvalue",
//                           s[i].substring("returnvalue=".length(), s[i].length()));
//            }
            else
            if (s[i].startsWith("preservice=")) {
                paras = s[i].substring("preservice=".length(), s[i].length());
                arrParas = new String[0];
                if (paras != null && paras.length() > 0)
                    arrParas = paras.split(",");

                retMap.put("preservice", arrParas);

            }
            else
            if (s[i].startsWith("paras=")) {
                paras = s[i].substring("paras=".length(), s[i].length());
                arrParas = new String[0];
                if (paras != null && paras.length() > 0)
                    arrParas = paras.split(",");

                retMap.put("paras", arrParas);

            }
            else
            if (s[i].startsWith("wfparas=")) {
                wfparas = s[i].substring("wfparas=".length(), s[i].length());
                arrWfparas = new String[0];
                if (wfparas != null && wfparas.length() > 0)
                    arrWfparas = wfparas.split(",");
                retMap.put("wfparas", arrWfparas);
            }
//            else
//            if (s[i].startsWith("parasout=")) {
//                paras = s[i].substring("parasout=".length(), s[i].length());
//                arrParas = new String[0];
//                if (paras != null && paras.length() > 0)
//                    arrParas = paras.split(",");
//
//                retMap.put("parasout", arrParas);
//
//            }
//            else
//            if (s[i].startsWith("wfparasout=")) {
//                wfparas = s[i].substring("wfparasout=".length(), s[i].length());
//                arrWfparas = new String[0];
//                if (wfparas != null && wfparas.length() > 0)
//                    arrWfparas = wfparas.split(",");
//                retMap.put("wfparasout", arrWfparas);
//            }
        }
        return retMap;
    }


    /**
     * 获取后继节点配置的业务服务名称列表
     * @param curNodeId String 当前节点标识
     * @return List, String
     */
    public List getSufBusinessServices(String curNodeId)
    {
        try
        {   
            ArrayList listServcies = new ArrayList();
            listServcies.add("baseService01");
            listServcies.add("baseService02");
            listServcies.add("baseService03");
            listServcies.add("baseService04");
            return listServcies;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * 获取前继节点配置的业务服务名称列表
     * @param curNodeId String 当前节点标识
     * @return List, String
     */
    public List getPreBusinessServices(String curNodeId)
    {
        try
        {   
            ArrayList listPreServcies = new ArrayList();
            listPreServcies.add("bussService02");
            listPreServcies.add("bussService55");
            return listPreServcies;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return null;
        }
    }


    /**
     * 获取指定服务的输出参数名称及类型列表
     * @param serviceName String 服务名称
     * @return List, String[类型][名称]
     */
    public List getServiceOutParamsByName(String serviceName)
    {
        try
        {
            ArrayList listOutParams = new ArrayList();
            if("bussService02".equals(serviceName))
            {
                String[] out = {"String", "name"};
                listOutParams.add(out);
                out = new String[2];
                out[0] = "boolean";
                out[1] = "isGood";
                listOutParams.add(out);
                out = new String[2];
                out[0] = "int";
                out[1] = "price";
                listOutParams.add(out);
            }
            if("bussService55".equals(serviceName))
            {
                String[] out = {"String", "name"};
                listOutParams.add(out);
                out = new String[2];
                out[0] = "Address";
                out[1] = "address";
                listOutParams.add(out);
                out = new String[2];
                out[0] = "Date";
                out[1] = "senddate";
                listOutParams.add(out);
            }
            return listOutParams;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return null;
        }
    }

    /**
     * 获取指定服务的输入参数名称及类型列表
     * @param serviceName String 服务名称
     * @return List，String[类型][名称]
     */
    public List getServiceInParamsByName(String serviceName)
    {
        try
        {
            ArrayList listInParams = new ArrayList();
            if("baseService01".equals(serviceName))
            {
                String[] out = {"int", "length"};
                listInParams.add(out);
                out = new String[2];
                out[0] = "int";
                out[1] = "width";
                listInParams.add(out);
            }
            if("baseService02".equals(serviceName))
            {
                String[] out = {"String", "name"};
                listInParams.add(out);
                out = new String[2];
                out[0] = "int";
                out[1] = "type";
                listInParams.add(out);
            }
            return listInParams;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return null;
        }
    }


    /**
     * 取得节点配置的数据映射信息
     * @param nodeId String 节点标识
     * @return String
     */
    public String getNodeDM(String nodeId)
    {
        try
        {
            return null;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            return null;
        }
    }


}
